from LeetCoder import *


class FrequencyTracker:

    def __init__(self):
        self.map = defaultdict(int)
        self.cnt = defaultdict(int)

    def add(self, number: int) -> None:
        if number in self.map:
            t = self.map[number]
            if t in self.cnt and self.cnt[t] > 0:
                self.cnt[t] -= 1
        self.map[number] += 1
        t = self.map[number]
        self.cnt[t] += 1

    def deleteOne(self, number: int) -> None:
        if number not in self.map or self.map[number] == 0:
            return
        t = self.map[number]
        if t in self.cnt and self.cnt[t] > 0:
            self.cnt[t] -= 1
        if number in self.map:
            self.map[number] -= 1
        t = self.map[number]
        self.cnt[t] += 1

    def hasFrequency(self, frequency: int) -> bool:
        if frequency in self.cnt and self.cnt[frequency] > 0:
            return True
        return False


s = FrequencyTracker()

s.add(3)
s.add(3)
s.hasFrequency(2)
